//
//  @ Project : Galaxy Star Trading System
//  @ File Name : MsgManager.h
//  @ Date : 2014/9/5
//  @ Author :
//
//


#if !defined(_CMSGMANAGER_H_H)
#define _CMSGMANAGER_H_H

#include "MsgHandler.h"

namespace GSTrader
{
	namespace TradeStrategy
	{
		typedef function<void(CMsg*)> MsgProcessHandler;
		class  CMsgManager : public CMsgHandler
		{
		public:
			CMsgManager(CFramework* pFramework, CMsgBus* pMsgBus);
			virtual ~CMsgManager();

		public:
			void Start();
			void SusPend();
			void Stop();
			void Resume();

			void Clear();
			bool FilterMsg(CMsg* pMsg);
		private:
			void ProcessThread();
			void OnMsg(CMsg* pMsg);
			void InitMsgHandler();
	
		private:
			mutex m_mutex;

			thread* m_pThread;
			atomic<EThreadRunStatus> m_pThreadRunStatus;

			CMsgDispatch* m_pMsgDispatch;

			CMsgFilter* m_pMsgFilter;
			map<int, MsgProcessHandler> m_MsgHandle;

			uint32 m_uMsgCount;
			atomic<int> m_nStatus;

		private:
			friend class CMsgBuffer;
			friend class CFramework;
			friend class CStrategySessionManager;
		};
	}
}

#endif // _CMSGMANAGER_H_H